/*
 * @Author: 晴鸢. 3013433857@qq.com
 * @Date: 2025-09-02 11:34:57
 * @LastEditors: 晴鸢. 3013433857@qq.com
 * @LastEditTime: 2025-09-03 12:55:48
 * @FilePath: /Learn/signal/mysignal.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<string>
#include<unistd.h>
#include<stdlib.h>
#include<signal.h>
#include<sys/types.h>
using namespace std;
void Usage(string proc)
{
    cout<<"Usage:\n\t"<<proc<<"signum pid\n\n";
}

void myheader(int signo)
{
    cout<<"process get a signal: "<<signo<<endl;
}

//mykill signum pid
int main(int argc,char*argv[])
{
    //signal(2,myheader);
    
    int cnt=0;
    while(1)
    {
        cout<<"I am a process,pid: "<<getpid()<<endl;
        sleep(1);
        cnt++;
        if(cnt%2==0)
        {
            abort();
            //kill(getpid(),2);
            //raise(2);
        }
    }
    /*
    if(argc!=3)
    {
        Usage(argv[0]);
        exit(1);
    }
    int signum=stoi(argv[1]);
    pid_t pid=stoi(argv[2]);

    int n=kill(pid,signum);
    if(n==-1)
    {
        perror("kill");
        exit(1);
    }
    */
    return 0;
}